package logic

import (
	"context"
	"gorm.io/gorm"
	"library/models/mysql"

	"library/libraryrpc/internal/svc"
	"library/libraryrpc/libraryrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserPerfectLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserPerfectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserPerfectLogic {
	return &UserPerfectLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserPerfectLogic) UserPerfect(in *libraryrpc.UserPerfectRequest) (*libraryrpc.UserPerfectResponse, error) {
	// todo: add your logic here and delete this line

	user := mysql.User{
		Model: gorm.Model{ID: uint(in.UserId)},
		Name:  in.Name,
		Sex:   in.Sex,
	}
	mysql.DB.Updates(&user)
	return &libraryrpc.UserPerfectResponse{
		UserId: int64(user.ID),
	}, nil
}
